package PTA_JAVA.JavaA.Javademo5;

import java.util.*;

class Main {
    static int[] arr = new int[0];
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        while (sc.hasNextLine()) {
            String s = sc.nextLine();
            if (s.equals("fib")) {
                fib(Integer.parseInt(sc.nextLine()));
            } else if (s.equals("sort")) {
                sort(sc.nextLine().split(" "));
            } else if (s.equals("search")) {
                int a = sc.nextInt();
                sc.nextLine();
                search(a);
            } else if (s.equals("getBirthDate")) {
                getBirthDate();
            } else {
                System.out.println("exit");
                System.exit(0);
            }
        }
    }

    private static void getBirthDate() {
        int n=sc.nextInt();
        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String number = sc.nextLine();
            String year = number.substring(6, 10);
            String month = number.substring(10, 12);
            String day = number.substring(12, 14);
            System.out.println(year + "-" + month + "-" + day);
        }
    }

    public static void fib(int n) {
        int s = 0, a = 0, b = 1;
        System.out.print(b);
        for (int i = 1; i < n; i++) {
            s = a + b;
            a = b;
            b = s;
            System.out.print(" " + s);
        }
        System.out.println();
    }

    public static void sort(String[] s) {
        arr = Arrays.stream(s).mapToInt(Integer::parseInt).toArray();
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void search(int a){
        int f=0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==a){
                System.out.println(i);
                f=1;
                break;
            }
        }
        if(f==0){
            System.out.println("-1");
        }
    }
}

